const {Router} = require('express');
const router = Router();
const query = require('../utils/mysql');

// 一、回调写法
const sql = 'select * from userlist';
/* router.get('/',(req,res)=>{
    query(sql,function(result){
        res.send({
            code:1,
            msg:"success",
            data:result
        })
    })
}) */

// 二、async/await
router.get('/',async(req,res)=>{
    try{
        const result = await query(sql);
        res.send({
            code:1,
            msg:"success",
            data:result
        })
    }catch(err){
        res.send({
            code:0,
            msg:"fail",
            data:err
        })
    }
})



module.exports = router;
